﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using ServerObjects;

namespace WcfService1
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        DateTime GetServerTime();
        
        [OperationContract]
        byte[] GetInitialGameState(int game);

        //[OperationContract]
        //byte[] GetLatestGameState(int game);

        [OperationContract]
        int GetCurrentGameTurn(int gameId);

        [OperationContract]
        List<MapDto> GetMaps();

        [OperationContract]
        int CreateGame(int mapId, string gameName, int turnLimit, TimeSpan turnTimeLimit);

        [OperationContract]
        List<GameDto> GetGames();

        [OperationContract]
        GameDto GetGame(int gameId);

        [OperationContract]
        List<TurnOrdersDto> GetAllOrders(int gameId);

        [OperationContract]
        List<UnitOrderDto> GetOrders(int gameId, int turn);

        [OperationContract]
        bool ReceiveOrders(int gameId, int turn, int factionId, List<UnitOrderDto> orders);

        [OperationContract]
        bool ReceiveOrder(int gameId, int turn, int factionId, UnitOrderDto order);

        [OperationContract]
        bool DeleteOrder(int gameId, int turn, int unitId);

        [OperationContract]
        void EndTurn(int gameId, int turn);

        [OperationContract]
        void EndGame(int gameId);
    }

    [DataContract]
    public class MapDto
    {
        [DataMember]
        public int Id;
        [DataMember]
        public string Name;

        public MapDto(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }

    [DataContract]
    public class TurnOrdersDto
    {
        [DataMember]
        public int Turn;

        [DataMember] 
        public List<UnitOrderDto> UnitOrderDtos;

        public TurnOrdersDto(int turn, List<UnitOrderDto> orders)
        {
            Turn = turn;
            UnitOrderDtos = orders;
        }
    }

    [DataContract]
    public class FactionDto
    {
        [DataMember]
        public int Id;
        [DataMember]
        public string Name;

        public FactionDto()
        {
        }

        public FactionDto(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }

    [DataContract]
    public class GameDto
    {
        [DataMember] public int Id;
        [DataMember] public string Name;
        [DataMember] public int Turn;
        [DataMember] public int TurnLimit;
        [DataMember] public DateTime TurnEnds;
        [DataMember] public List<FactionDto> FactionDtos;

        public GameDto()
        {
        }

        public GameDto(int id, string name, int turn, int turnLimit, DateTime turnEnds, List<FactionDto> factionDtos)
        {
            Id = id;
            Name = name;
            Turn = turn;
            TurnLimit = turnLimit;
            TurnEnds = turnEnds;
            FactionDtos = factionDtos;
        }

        //public DateTime TurnEnds
        //{
        //    get 
        //    {
                
        //        var turnEnds = DateTime.Now;
        //        for (var i = 0; i < Turn; i ++)
        //            turnEnds = turnEnds.Add(TurnTimeLimit);
        //        return turnEnds;
        //    }
        //}

    }

    
}
